package com.tiger.controller;

import com.tiger.pojo.JsonResult;
import com.tiger.service.ShiroUserRealm;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/user/")
@ResponseBody
public class LoginController {

	
	@Autowired
	private ShiroUserRealm shiroUserRealm;

	@RequestMapping("doLogin")
	public JsonResult doLogin(String userName, String password) {
		System.out.println("==doLogin===");
		//获取Subject对象(负责提交客户端的账号信息)
		Subject subject=SecurityUtils.getSubject();
		UsernamePasswordToken token=new UsernamePasswordToken();
		token.setUsername(userName);
		token.setPassword(password.toCharArray());
		//提交账号信息给securityManager对象
		subject.login(token);
		return new JsonResult("login ok");
	}
}
